/*
 * 
 * 
 * 
 */
package com.hboxs.asl.entity;

import com.fasterxml.jackson.annotation.JsonValue;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity - 查看答案
 */
@Entity
@Table(name = "xx_yiyuan_trade")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_yiyuan_trade_sequence")
public class YiYuanTrade extends BaseEntity {

    private static final long serialVersionUID = -7907809876561149722L;

    /**
     * 支付状态
     */
    public enum PaymentStatus {
        /**
         * 未支付
         */
        unpaid,

        /**
         * 已支付
         */
        paid;

        private static Map<String, YiYuanTrade.PaymentStatus> map = new HashMap<>();

        static {
            map.put("未支付", unpaid);
            map.put("已支付", paid);
        }

        public static YiYuanTrade.PaymentStatus forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, YiYuanTrade.PaymentStatus> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }

            return "";
        }

        public static YiYuanTrade.PaymentStatus getDefault() {
            return YiYuanTrade.PaymentStatus.unpaid;
        }

    }

    /**
     * 支付方式名称
     */
    private String paymentMethodName;

    /**
     * 支付方式
     */
    private com.hboxs.asl.entity.PaymentMethod paymentMethod;

    /**
     * 编号
     */
    private String sn;

    /**
     * 易问易答id
     */
    private Long questionId;

    /**
     * 支付状态
     */
    private PaymentStatus paymentStatus;

    /**
     * 购买者
     */
    private Member buyer;

    private BigDecimal price;

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Long getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Long questionId) {
        this.questionId = questionId;
    }

    public PaymentStatus getPaymentStatus() {
        return paymentStatus;
    }

    public void setPaymentStatus(PaymentStatus paymentStatus) {
        this.paymentStatus = paymentStatus;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public Member getBuyer() {
        return buyer;
    }

    public void setBuyer(Member buyer) {
        this.buyer = buyer;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public String getPaymentMethodName() {
        return paymentMethodName;
    }

    public void setPaymentMethodName(String paymentMethodName) {
        this.paymentMethodName = paymentMethodName;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public PaymentMethod getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
    }
}